Composite values use a common syntax consisting of a tuple
of scalars followed by one of the postfix type decorations used for composite
variables. The decoration can be applied to a single real value or
variable (no parentheses required), or to a tuple containing any number of
scalars. However, the display form is unique to each composite type.
Being a sort of collection, indexing can be used on composite values
to extract individual items. Special forms of indexing are also
provided to conform more closely to mathematical notation (see §2.6.2).
2.7.1 Complex Values
The composite form of complex value is known as complex-I. Another form, complex-J, is described
here because of its close mathematical relation to complex-I. The ⅉ notation comes from the
engineering domain, where ⅈ is traditionally used to mean current.
In Myron, ⅉ is simply a real constant.
The forms can be mixed, but there
is an expectation that one or the other will be used.
When mixed, complex-J expressions
are coerced to complex-i.
The syntax of complex-i values is given in Figure
2.35. The expressions in the tuple represent the real and
imaginary parts of a complex number:
(4, 3)ⅈ. If the operand is a single real, the real part is taken to be zero. If
the operand is a variable name, the result is a typed variable.
In addition, the type decoration ⅈ can
stand alone. If ⅈ is used as a standalone primary, it is given
the meaning
(0,1)ⅈ.
In contrast, a complex-j value is given by the simple symbol ⅉ. It has
the complex-i value (0,1)ⅈ.
Figure 2.35 Complex-I values
Complex-I values have two special cases for display. One is when the
real part is 0, and the other is when the real part is 0 and the
imaginary part is 1. That is,
(0,π÷2)ⅈ
displays as
(0, ℼ÷2)ⅈ
and
(0,1)i
displays as
ⅈ.
Mathematicians often use a notation including an additive operator,
like
4+7ⅈ, to represent the real and imaginary parts of complex numbers. In Myron, this is a complex-I expression (or rather, an expression of
type complex-I), but it is not in its simplest form; that is, it is not a
complex-I value. The expression is a binary addition operator with a
real and a complex-i operand. This is evident from its syntactic
representation:
4+(0,7)ⅈ. In fact, the expression represents the same value as
7ⅈ+4. Simplified, both expressions become
(4, 7)ⅈ.
Contrast this with the complex-J expression 4+7⋅ⅉ, a real expression in which
ⅉ is just a real constant.
Note the difference between the complex-I value
(0,a)ⅈ
and the complex variable
aⅈ. These have a similar display:
(0, a)ⅈ
and
aⅈ
but the variable a is real in the first case and complex in
the second. Carrying this a bit further, if the two expressions are
indexed, as in
(0, a)ⅈ[1]
(entered as
(0,a)ⅈ[1]) and
aⅈ[1]
(entered as
aⅈ[1])), simplifying the first produces the real a but the second
cannot be simplified; it can only be evaluated. Provided there is a
definition in the workspace to which
aⅈ
can be bound, an item from that definition can be extracted by
indexing.
2.7.2 Radial Values
Radial values consist of a
magnitude and one or more angles. A radial value with one angle
represents polar co-ordinates. A radial value with two angles
represents spherical co-ordinates. The display form is a tuple with an
overhead arrow. Like complex values, radial values have abbreviated
input forms when the magnitude is zero.
While indexing can be used to extract individual items, a more
mathematical notation is also provided. The magnitude can be extracted
using the magnitude operator:
|(2, 3)ɽ|
is 2; and the first angle can be extracted using the angle operator:
∠(2, 3)ɽ
is 3. Other angles can be extracted by subscripting the angle
operator:
∠_1(2,3,4)ɽ
is 4.
2.7.3 Vector Values
Vector values consist of 1 or
more scalars. The display form is a tuple with angle brackets. Vectors
have an abbreviated input form when there is only one dimension.
Examples are (1)ʋ (input as (1)v) and (1, 2, 3)ʋ (input as (1,2,3)v)